<?php
/**
 * 码库Lib类
 * @author xiayuanjun@shopex.cn
 * @version 1.0
 */
class material_codebase {

    /**
     * 获取特性列表方法
     *
     * @param Null
     * @return Array
     */
    public function getCodeList(){
        return array(
            array('type'=>1,'name'=>'条码'),
            array('type'=>2,'name'=>'批次'),
        );
    }

    /**
     * 获取条码的类型值
     *
     * @param Null
     * @return Int
     */
    public static function getBarcodeType(){
        return 1;
    }

    /**
     * 获取条码的类型值
     *
     * @param Null
     * @return Int
     */
    public static function getStorageListType(){
        return 2;
    }

    /**
     * 根据保质期条码检查是否是这个物料的
     *
     * @param String $code
     * @return Boolean
     */
    public function checkCodeExist($code){
        $codebaseObj = app::get('material')->model('codebase');
        $code_info = $codebaseObj->getList('code',array('code'=>$code));
        return $code_info ? true : false;
    }

    /**
     * 根据保质期条码检查是否是这个物料的
     *
     * @param Int $bm_id
     * @param String $code
     * @return Boolean
     */
    public function checkBmHasThisStorageListBn($bm_id, $code){
        $codebaseObj = app::get('material')->model('codebase');
        $code_info = $codebaseObj->getList('code',array('type'=>2,'code'=>$code,'bm_id'=>$bm_id));
        return $code_info ? true : false;
    }

    public static function getBarcodeBybn($bn){
        $materialObj= app::get('material')->model('basic_material');
        $codebaseObj = app::get('material')->model('codebase');
        $material = $materialObj->dump(array('material_bn'=>$bn),'bm_id');
        if($material){
            $code_info = $codebaseObj->dump(array('type'=>1,'bm_id'=>$material['bm_id']),'code');
            return $code_info['code'];
        }
    }
    
    public static function getBnBybarcode($barcode){
        $materialObj= app::get('material')->model('basic_material');
        $codebaseObj = app::get('material')->model('codebase');
        $code_info = $codebaseObj->dump(array('type'=>1,'code'=>$barcode),'bm_id');
         
        if($code_info){
            $material = $materialObj->dump(array('bm_id'=>$code_info['bm_id']),'material_bn');
             
            return $material['material_bn'];
        }
    }
}
